#ifndef _MEMCACHE_H_
#define _MEMCACHE_H_

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

#include "funcs.h"				/* this module depends on 'funcs' module */
#include "protocol_basic.h"		/* this module depends on 'protocol_basic' module */


#define MC_GOSSIP_DEBUG



#define MAX_KEYS		50		/* max keys that can hold */
#define MAX_CMD_LEN		512		/* length limit of command string */


/* 
 * string macro.
 * not in use now.
 */
#define STRING(strlen)			struct{char str[strlen + 1];}

#define STR_GET(string)			(string.str)
#define STR_SET(str, val)		(memmove(str, val, sizeof(str) - 1)); \
								(str[sizeof(str) - 1] = '\0')	

#define STR_SET_CHAR(string, index, val)	(string.str[index] = val)
#define STR_GET_CHAR(string, index)			(string.str[index])


/* command <-> function mapping part */
typedef size_t CMD_PROCESSING(PROTOCOL *);

typedef struct cmd_function
{
	const char *command;		/* command name */
	CMD_PROCESSING *func_ptr;	/* pointer to the proceesing function */
}CMD_FUNCTION;


/* the command enum of memcache protocol */
typedef enum mc_cmd
{
	/* 
     * memcache original commands.
     * all commands starts from 1, because of the 0 is defined as invalid command.
     */
    _cmd_null,
	_cmd_set,
	_cmd_add,
	_cmd_replace,
	_cmd_append,
	_cmd_prepend,
	_cmd_cas,
	_cmd_get,
	_cmd_gets,
	_cmd_delete,
	_cmd_incr,
	_cmd_decr,
	_cmd_stats,
	_cmd_flush_all,
	_cmd_version,
	_cmd_quit,
	
	/* expansion commands for gossip */
	_cmd_reg,
	_cmd_disreg,
    _cmd_gspset
	
}MC_CMD;



/* the final memcache info package(processed) */
typedef struct mc_info
{
	/* command information */
	MC_CMD cmd;				/* command sign */
	int key_count;
	char *keys[MAX_KEYS];	/* command: keys */
	char *flag;				/* command: flag */
	char *exptime;			/* command: exptime */
	char *cas_unqiue;
	char *args;
	char *name;
	size_t bytes;
	char noreply;
	uint64_t value;
	int ttl;
	int port;
	char *host;
	char *time;
    int peer_id;
    int src_id;
    int sender_id;
    uint64_t msg_id;
	
	/* control block */
	char is_submit;		/* indicates whether submit success */
	
	
}MC_INFO;


#endif


